<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ page import="database.Article"%>
<%@ page import="database.Comment"%>
<%@ page import="database.DatabaseManager"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.FileReader" %>
<%@ page import="java.util.List" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<%
	request.setCharacterEncoding("utf-8");
	int articleID = Integer.parseInt(request.getParameter("articleID"));
	//String creator = request.getParameter("creator");
	//String time = request.getParameter("time");
	//String title = request.getParameter("title");
	Article article = DatabaseManager.articleQueryByArticleID(articleID);
%>
<title><%=article.getTitle() + "-清风品道" %></title>
</head>
<body>
	<jsp:include page="./nav.jsp"></jsp:include>
	<div style="min-height:410px">
	<table width="700px" align="center">
		<%
			String permission = (String)session.getAttribute("permission");
			if(permission != null && permission.equals("a")) {
		%>
		<tr>
			<td align="right">
				<a href="./editArticle.jsp?articleID=<%=articleID %>">编辑</a>
			</td>
		</tr>
		<%
			}
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		%>
		<tr>
			<td align="left">
				<div style="width:700px; text-align:center">
					<h3><%=article.getTitle() %></h3>
					<hr />
					<p>日期：<%=formatter.format(article.getPublishTime()) %>&nbsp;&nbsp;作者：<%=article.getCreator() %></p>
				</div>
				<div style="width:700px; text-align:left">
					<%
						BufferedReader in = new BufferedReader(new FileReader(application.getRealPath("/") + "/file/" + articleID));
						if(in != null) {
							String line = null;
							while((line = in.readLine()) != null) {
								out.print(line);
							}
						}
					%>
				</div>
				<div style="width:700px; text-align:left">
					<hr />
					<form action="NewCommentServlet" method="post">
						<input type="hidden" name="articleID" id="articleID" value="<%=articleID %>" />
						<textarea rows="5" cols="84" name="comment" id="comment"></textarea>
						<br />
						<div style="float:right">
							<input type="submit" value="发表评论" />
						</div>
					</form>
				</div>
				<br />
				<%
					List<Comment> list = DatabaseManager.commentQueryByArticleID(articleID);
					for(Comment comment : list) {
				%>
				<div style="width:700px; background-color:#dcdcdc; text-align:left">
					<p>&nbsp;<%=comment.getCommenter() %>&nbsp;&nbsp;发表于<%=formatter.format(comment.getPublishTime()) %></p>
				</div>
				<div style="width:700px; background-color:#f0ffff; text-align:left">
					<pre><%=comment.getContent() %></pre>
				</div>
				<br />
				<%
					}
				%>
			</td>
		</tr>
	</table>
	</div>
	<jsp:include page="./bottom.jsp"></jsp:include>
</body>
</html>